<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
com.jxtti.model.User userInfo = com.jxtti.utils.AuthUtil.getUserInfo(request);
String orgId=null;
if(userInfo.getDistrictId()==null || userInfo.getDistrictId().equals("0")){ //非超管
	orgId=userInfo.getOrgId().toString();
}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>科室介绍</title>
		<%@ include file="../../../common/Admin-list.jsp"%>		 
		<script type="text/javascript" src="<%=bpath %>Scripts/jquery/jquery.form.js"></script> 		 
		<script type="text/javascript">	
		var subUrl="../DeptsIntroduce/save.json";
		$(function(){					
			// 组织机构						
			$('#fk_orgId').combotree({
				 url: '../district/findByPidAll.json',			
				 panelHeight:'300', 
	             editable: true , 	                         
				 onClick: function (node) { 			      	
			     	$("#name").val($("#fk_orgId").combotree("getText"));			    	
		    		var aj = $.ajax({  
		        	    url:'../DeptsIntroduce/queryAll.json',  
		        	    data:{  
		        	    	fk_orgId :$("#fk_orgId").combotree("getValue")
		        	    },  
		        	    type:'post',  
		        	    cache:false,  
		        	    dataType:'json',  
		        	    success:function(data) { 		        	    	
		        	    	if(data!=null&&data.length!=0){
		        	    		alert("该科室已经添加过了，请重新选择");
		        	    		$('#fk_orgId').combotree('clear');
		        	    	}
		        	     },  
		        	     error : function() {  
		        	          alert("异常！");  
		        	     }  
		        	});			    
			   	 }, //全部折叠
	           	 onLoadSuccess: function (node, data) {	           			           		 
	           		 $('#fk_orgId').combotree('tree').tree("collapseAll"); 
	           		 $("#name").val($("#fk_orgId").combotree("getText"));
	             }
			});
			if(<%=orgId %>!=null){ //是否管理员
				$("#fk_orgId").combotree("setValue",<%=orgId %>);	
				$("#fk_orgId").combotree('disable');
			}			
					
			if('${data.type}'!=null&&'${data.type}'=="edit"){ //编辑模块				
				$("#lblTitle").html('编辑科室');				
				if('${data.deptsIntroduce.visible}'=="0"){
					$("#visible").attr("checked",false);
				}			
				$("#id").val('${data.deptsIntroduce.id}');		
				$("#name").val('${data.deptsIntroduce.name}');				
				$('#fk_orgId').combotree('setValue', '${data.deptsIntroduce.fk_orgId}'); 								
				subUrl="../DeptsIntroduce/update.json";
			}
			
		});
		
		function lnbSave(st){
			$("#addForm").ajaxSubmit({
				url:subUrl,
				type:"POST",
				async:false,
				beforeSubmit:checkForm,
				contentType:"application/x-www-form-urlencoded;charset=UTF-8",
				error:function(){},
				success:function(data){
					if(data.success==true){
						showTip("保存成功，返回列表页面！","succeed");					    	
					}else{
						//showTip("操作失败","warning");  
						art.dialog.alert('保存失败，请确认填写正确！');
					}
				}
			});		
				
		}
			
		function checkForm(){
			var flag=$('#addForm').form('validate');
			return true;
		}
				
		//消息提示  
		function showTip(mess,icon) {  
		    art.dialog({  
		        id : 'Tip',  
		        title : '消息',  
		        fixed : true,  
		        lock : true,  
		        opacity: .2,  
		        content : mess,  
		        icon : icon,  
		        time : 1  
		    });  
		    setTimeout('originReload()', 1000);  
		}  
		
		//重载来源页面  
		function originReload(){  
		    var win = art.dialog.open.origin;		    
		    win.location.reload();  
		}	
		</script>
		
</head>
<body>
<!---->
<div>
	<div id="tab">
        <ul>
            <li class="Current">
            	<a href="#" onfocus="this.blur()">
            		<span id="lblTitle">科室介绍 </span>
            	</a>
            </li>
        </ul>
    </div>  
    <div id="menu">
        <ul>          
            <li>
            	<a href="javascript:lnbSave(0)" >
            		<span><img src="<%=basePath %>pages/Admin/Images/Icon/save.gif" alt="Save" />保存</span>
            	</a>
            </li>              
        </ul>
    </div>   
    
    <div id="middle"> 
    <form action="../DeptsIntroduce/save.json" id="addForm" name="addForm" method="post" >   
    <div class="editor">
        <table class="eTable">
            <tr class="eTr">
                <td class="name">         
                	 <label id="Label21" >网站显示</label>           
                </td>
                <td>	
                	 <input id="id" name="id" type="hidden"></input>
                	 <input id="visible" type="checkbox" name="visible" checked="checked" value="1"  style="vertical-align:middle;"/>
                	 <label for="issue">网站显示</label>                	                	 
				</td>
            </tr>      
            <tr class="eTr">
                <td class="name">
                    <label id="Label2" >所属科室</label></td>
                <td>
                	<select id="fk_orgId" name="fk_orgId" class="easyui-combotree"  style="width:250px;"></select>
                	&nbsp;&nbsp;
                	<input id="name" name="name" type="hidden" ></input>
                </td>
            </tr>        
            <tr class="eTr" id="trRemark">
                <td class="name" valign="top">
                    <label id="Label5" >主要职责：</label>
                </td>
                <td>                	
                    <textarea cols=40 rows=15 style="height:200px;" id="duties" name="duties">${data.deptsIntroduce.duties}</textarea>
                </td>
            </tr> 
            <tr class="eTr" id="trRemark">
                <td class="name" valign="top">
                    <label id="Label5" >联系方式：</label>
                </td>
                <td>
                    <textarea cols=40 rows=15 style="height:150px;"  id="contact" name="contact">${data.deptsIntroduce.contact}</textarea>
                </td>
            </tr> 
        </table>
        
    </div>
    </form> 
    </div>
</div>
</body>
</html>